<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面试</title>
</head>

<body>
    <!-- IMPORT JS -->
    <script>
        /* 第一题：去除字符串首尾空格，不允许使用trim函数 */
        String.prototype.myTrim = function myTrim() {
            return this.replace(/(^\s+|\s+$)/g, "");
        };

        /* 第二题：URL问号传参解析 */
        String.prototype.queryURLParams = function queryURLParams() {
            let obj = {};
            this.replace(/#([^?&#=]+)/g, (_, $1) => obj['HASH'] = $1);
            this.replace(/([^?&#=]+)=([^?&#=]+)/g, (_, $1, $2) => obj[$1] = $2);
            return obj;
        };

        /* 第三题：递归题目 */
        /* const computed = (num, age = 10) => {
            if (num === 1) return age;
            num--;
            return computed(num, age + 2);
        };
        // console.log(computed(8)); //24 */

        /* 第四题：阿拉伯数字转换为中文数字 */
        /* const computed = num => {
            num = num + '';
            let arr = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
            let arr2 = ['', '十', '百', '千', '万'];
            let result = num.split('').reverse().map((item, index) => {
                let char = arr[item];
                if (index > 0 && char !== '零') {
                    char += arr2[index];
                }
                return char;
            });
            result.reverse();
            return result.join('');
        };
        console.log(computed(20876)); //'二万零八百七十六' */

        /* 第五题：阶乘 */
        /* const factorial = n => {
            if (n === 1) return 1;
            return n * factorial(n - 1);
        };
        console.log(factorial(10)); //3628800 */

        /* 第六题：千分符 */
        /* String.prototype.millimeter = function millimeter() {
            let result = this.replace(/\d{1,3}(?=(\d{3})*$)/g, val => val + ',');
            return result.substring(0, result.length - 1);
        };
        let str = '12343424567';
        console.log(str.millimeter());//'12,343,424,567' */
    </script>
</body>

</html>